﻿using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace Expect.VisualStudio.Extensions.Commands.Handlers
{
    public class GotoFixtureHandler : ResolvedFixtureCommand
    {
        public GotoFixtureHandler(IExpectPackage pkg)
            : base(pkg, CommandIDs.cmdidGoToFixture)
        {
        }

        public override string DisplayText
        {
            get
            {
                return "Go to fixture implementation";
            }
        }

        public override void ExecuteCommand(SelectionResolution resolution)
        {
            var dte = (DTE2)GetVSService(typeof(SDTE));

            if (resolution.Target != null && resolution.FixtureResKind != FixtureResolutionKind.None && resolution.FixtureResKind != FixtureResolutionKind.Unknown)
            {
                //string filename = _resolution.Target.FileNames[0];
                var window = resolution.Target.Open();

                if (resolution.TargetPoint != null)
                {
                    EditorHelper.SetCursorTo(dte, window, resolution.TargetPoint.Line, 0);
                }
                window.Activate();
                //var window = dte.OpenFile(null, filename);                
            }
        }
    }
}
